<template>
	<div>
		<el-dialog title="分 享" :visible.sync="dialogFormVisible">
		  <el-form :model="form">
				<vue-qr ref="Qrcode" 
            :text="dataObj.text" 
            :logoSrc="dataObj.logo" 
            :callback="back" qid="testQrId"
				></vue-qr>
				<p class="urlMessage">链接：<a :href="url" class="url" target="_blank">{{url}}</a></span></p>
		  </el-form>
		  <div slot="footer" class="dialog-footer">
		    <el-button type="primary" @click="dialogHidden">确 定</el-button>
		  </div>
		</el-dialog>
	</div>
</template>

<script>
	import bus from '@/bus/bus.js'
	import VueQr from 'vue-qr'
	export default{
		data(){
			return{
				solo:'',
				imgArr:'',
				url:'',
				dataObj: {
				        text: 'https://blog.csdn.net/weixin_43760328/rss/list',
				        logo: require('@/assets/pngImg/小鸡.png')
				      },
				dialogFormVisible: false,
				form: {
				  name: '',
				  region: '',
				  date1: '',
				  date2: '',
				  type: [],
				  resource: '',
				  desc: ''
				},
				formLabelWidth: '120px',
				message:'',
				arr:[]
			}
		},
		components:{
			VueQr
		},
		created() {
			bus.$on('shareForm',this.dialogShow)
			bus.$on('cancelShares',this.cancelShow)
		},
		methods:{
			open() {
				let that = this;
        this.$confirm(that.message+'，是否继续', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.shareMessage()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消分享'
          });          
        });
      },
			//取消分享
			cancelShow(arr){
				console.log('取消分享！')
				let Cdata = this.$imageClass.CcancelShare(arr)
				this.$http.patch('/api/ablum/all/picture',Cdata).then((res)=>{
					this.$message({
						type:'success',
						message:'取消分享成功！'
					})
					bus.$emit("shareFinish");
				})
			},
			dialogShow(arr,solo){
				if(solo == '1'){
					this.message = '此操作会分享选中照片'
				}else{
					this.message =  '此操作会分享出相册中的所有照片'
				}
				this.open()
				this.arr = arr;
			},
			dialogHidden(){
				this.dialogFormVisible = false
			},
			shareMessage(){
				let Cdata = this.$imageClass.Cshare(this.arr)
					this.$http.patch('/api/ablum/all/picture',Cdata).then((res)=>{
						console.log(res)
						this.url = this.$store.state.localhost+'ShareView/'+res.data.shareId
						this.dataObj.text = this.$store.state.localhost+'ShareView/'+res.data.shareId
						bus.$emit("shareFinish");
						this.dialogFormVisible = true;
						this.$message({
							type:'success',
							message:'分享成功！链接已生效！'
						})
					})
					
			},
			back(){
				
			}

		}
	}
</script>

<style scoped="scoped">
	.el-form{
		text-align: center;
	}
.el-dialog{
	text-align: center;
}
.url:hover{
	text-decoration: underline;
	color: #0000FF;
}
		
</style>
